

let first = document.querySelector('.first')
let second = document.querySelector('.second')
let fu = document.querySelector('.first-ul')


let info = {
    pageNum: '1',
    pageSize:'12',
    t: '1648700083105'

}

addList()
async function addList() {
    let res = await pAjax({
        url:'/vivo',
        dataType:'json',
        method:'POST',
        data:info
    })

    console.log(res);
    let str =`
    <ul class="first"></ul>`
    res.data.categoryInfo.firstNav.forEach(function(item){
        console.log(item.name);
        str +=`
        <li>${item.name}</li>
        `
    })
    first.innerHTML = str



    let shouji =`
    <ul class="second"></ul>`
    res.data.categoryInfo.secondNav.forEach(function(item){
        console.log(item.name);
        shouji +=`
        <li>${item.name}</li>
        `
    })
    second.innerHTML = shouji




    let yemian =`
    <ul class="second"></ul>`
    res.data.dataList.forEach(function(item){
        console.log(item.name);
        yemian +=`
        <li>
                        <a href="">
                            <img src="${item.images[0].bigPic}" alt="">
                        </a>
                        <p class="first">${item.skuName}</p>
                        <p class="bland">${item.promotion}</p>
                        <p class="last">￥${item.marketPrice}</p>
                    </li>
        `
    })
    fu.innerHTML = yemian
}



fu.addEventListener('click', e => {
    e = e || window.event
    let target = e.target || e.srcElement
    // console.log(target);
    // 判断点击的是不是li
    if (target.nodeName === 'LI') {
        // 代码能执行到这里 说明点击的是li
        // 在这里你要把你点击的和商品的id保存到浏览器中
        let srcImg=document.querySelector('img')
        let shoujim=document.querySelector('.first')
        let jiage= document.querySelector('.last')
        // 调转到详情页面
        window.location.href = '../views/detail.html'
    }
})


